164#ifndef WOLF_AUTODIFF_PUBLIC_JET_H_
165#define WOLF_AUTODIFF_PUBLIC_JET_H_
174#include <type_traits>
200template <
typename T,
int N,
typename U>
201struct std::common_type<T,
wolf::autodiff::Jet<U, N>> {
205template <
typename T,
int N,
typename U>
206struct std::common_type<
wolf::autodiff::Jet<T, N>, U> {
210template <
typename T,
int N,
typename U>
217template <
typename T,
int N>
230 explicit Jet(
const T& value) {
236 Jet(
const T& value,
int k) {
246 template <
typename Derived>
247 EIGEN_STRONG_INLINE
Jet(
const T&
a,
const Eigen::DenseBase<Derived>&
v)
296 Eigen::Matrix<T, N, 1>
v;
300 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
304template <
typename T,
int N>
313template <
typename T,
int N>
319template <
typename T,
int N>
325template <
typename T,
int N>
331template <
typename T,
int N>
337template <
typename T,
int N>
343template <
typename T,
int N>
349template <
typename T,
int N>
355template <
typename T,
int N>
361template <
typename T,
int N>
367template <
typename T,
int N>
373template <
typename T,
int N>
382 const T g_a_inverse = T(1.0) / g.
a;
383 const T f_a_by_g_a =
f.a * g_a_inverse;
384 return Jet<T, N>(f_a_by_g_a, (
f.v - f_a_by_g_a * g.
v) * g_a_inverse);
388template <
typename T,
int N>
390 const T minus_s_g_a_inverse2 = -s / (g.
a * g.
a);
391 return Jet<T, N>(s / g.
a, g.
v * minus_s_g_a_inverse2);
395template <
typename T,
int N>
397 const T s_inverse = T(1.0) / s;
398 return Jet<T, N>(
f.a * s_inverse,
f.v * s_inverse);
408#define WOLF_AUTODIFF_DEFINE_JET_COMPARISON_OPERATOR(op) \
409 template <typename Lhs, \
411 std::enable_if_t<PromotableJetOperands_v<Lhs, Rhs>>* = nullptr> \
412 constexpr bool operator op(const Lhs& f, const Rhs& g) noexcept( \
413 noexcept(internal::AsScalar(f) op internal::AsScalar(g))) { \
414 using internal::AsScalar; \
415 return AsScalar(f) op AsScalar(g); \
423#undef WOLF_AUTODIFF_DEFINE_JET_COMPARISON_OPERATOR
479inline bool isless(
double lhs,
480 double rhs)
noexcept(
noexcept(
std::isless(lhs, rhs))) {
510#ifdef WOLF_AUTODIFF_HAS_CPP20
530template <
typename T,
int N>
557template <
typename T,
int N>
562 T d =
fpclassify(g) == FP_ZERO ? std::numeric_limits<T>::infinity() : T(0);
574template <
typename T,
int N>
577 const T a_inverse = T(1.0) /
f.a;
582template <
typename T,
int N>
586 const T a_inverse = T(1.0) / (
f.a *
log(T(10.0)));
591template <
typename T,
int N>
594 const T a_inverse = T(1.0) / (T(1.0) +
f.a);
599template <
typename T,
int N>
602 const T tmp =
exp(
f.a);
607template <
typename T,
int N>
611 const T expa = tmp + T(1.0);
616template <
typename T,
int N>
619 const T tmp =
sqrt(
f.a);
620 const T two_a_inverse = T(1.0) / (T(2.0) * tmp);
625template <
typename T,
int N>
632template <
typename T,
int N>
635 const T tmp = -T(1.0) /
sqrt(T(1.0) -
f.a *
f.a);
640template <
typename T,
int N>
647template <
typename T,
int N>
650 const T tmp = T(1.0) /
sqrt(T(1.0) -
f.a *
f.a);
655template <
typename T,
int N>
658 const T tan_a =
tan(
f.a);
659 const T tmp = T(1.0) + tan_a * tan_a;
664template <
typename T,
int N>
667 const T tmp = T(1.0) / (T(1.0) +
f.a *
f.a);
672template <
typename T,
int N>
679template <
typename T,
int N>
686template <
typename T,
int N>
689 const T tanh_a =
tanh(
f.a);
690 const T tmp = T(1.0) - tanh_a * tanh_a;
698template <
typename T,
int N>
708template <
typename T,
int N>
717template <
typename T,
int N>
720 const T derivative = T(1.0) / (T(3.0) *
cbrt(
f.a *
f.a));
725template <
typename T,
int N>
728 const T tmp =
exp2(
f.a);
729 const T derivative = tmp *
log(T(2));
734template <
typename T,
int N>
737 const T derivative = T(1.0) / (
f.a *
log(T(2)));
745template <
typename T,
int N>
761template <
typename T,
int N>
773 return Jet<T, N>(tmp, x.
a / tmp * x.
v + y.
a / tmp * y.
v + z.
a / tmp * z.
v);
777template <
typename T,
int N>
817template <
typename Lhs,
typename Rhs, std::enable_if_t<CompatibleJetOperands_v<Lhs, Rhs>>* =
nullptr>
818inline decltype(
auto)
fmax(
const Lhs& x,
const Rhs& y)
820 using J = std::common_type_t<Lhs, Rhs>;
828#if defined(WOLF_AUTODIFF_HAS_CPP20)
829 return midpoint(J{x}, J{y});
831 return (J{x} + J{y}) *
typename J::Scalar(0.5);
840template <
typename Lhs,
typename Rhs, std::enable_if_t<CompatibleJetOperands_v<Lhs, Rhs>>* =
nullptr>
841inline decltype(
auto)
fmin(
const Lhs& x,
const Rhs& y)
843 using J = std::common_type_t<Lhs, Rhs>;
851#if defined(WOLF_AUTODIFF_HAS_CPP20)
852 return midpoint(J{x}, J{y});
854 return (J{x} + J{y}) *
typename J::Scalar(0.5);
863template <
typename Lhs,
typename Rhs, std::enable_if_t<CompatibleJetOperands_v<Lhs, Rhs>>* =
nullptr>
864inline decltype(
auto)
fdim(
const Lhs&
f,
const Rhs& g)
866 using J = std::common_type_t<Lhs, Rhs>;
869 return std::numeric_limits<J>::quiet_NaN();
877template <
typename T,
int N>
892template <
typename T,
int N>
932template <
typename T,
int N>
940template <
typename T,
int N>
948template <
typename T,
int N>
972template <
typename T,
int N>
979template <
typename T,
int N>
986template <
typename T,
int N>
994template <
typename T,
int N>
1004template <
typename Lhs,
typename Rhs, std::enable_if_t<CompatibleJetOperands_v<Lhs, Rhs>>* =
nullptr>
1015template <
typename Lhs,
typename Rhs, std::enable_if_t<CompatibleJetOperands_v<Lhs, Rhs>>* =
nullptr>
1026template <
typename Lhs,
typename Rhs, std::enable_if_t<CompatibleJetOperands_v<Lhs, Rhs>>* =
nullptr>
1037template <
typename Lhs,
typename Rhs, std::enable_if_t<CompatibleJetOperands_v<Lhs, Rhs>>* =
nullptr>
1048template <
typename Lhs,
typename Rhs, std::enable_if_t<CompatibleJetOperands_v<Lhs, Rhs>>* =
nullptr>
1057template <
typename Lhs,
typename Rhs, std::enable_if_t<CompatibleJetOperands_v<Lhs, Rhs>>* =
nullptr>
1066template <
typename T,
int N>
1073template <
typename T,
int N>
1080template <
typename T,
int N>
1082 "wolf::autodiff::IsFinite will be removed in a future Ceres Solver release. Please "
1083 "use wolf::autodiff::isfinite.")
1089template <
typename T,
int N>
1091 "wolf::autodiff::IsNaN will be removed in a future Ceres Solver release. Please use "
1092 "wolf::autodiff::isnan.")
1098template <
typename T,
int N>
1100 "wolf::autodiff::IsNormal will be removed in a future Ceres Solver release. Please "
1101 "use wolf::autodiff::isnormal.")
1108template <
typename T,
int N>
1110 "wolf::autodiff::IsInfinite will be removed in a future Ceres Solver release. "
1111 "Please use wolf::autodiff::isinf.")
1117#ifdef WOLF_AUTODIFF_HAS_CPP20
1132template <
typename T,
int N>
1133inline Jet<T, N> lerp(
const Jet<T, N>& a,
const Jet<T, N>& b,
const Jet<T, N>& t)
1135 return Jet<T, N>{lerp(a.a, b.a, t.a), (T(1) - t.a) * a.v + t.a * b.v + (b.a - a.a) * t.v};
1148template <
typename T,
int N>
1149inline Jet<T, N> midpoint(
const Jet<T, N>& a,
const Jet<T, N>& b)
1151 Jet<T, N> result{midpoint(a.a, b.a)};
1154 for (
int i = 0; i < N; ++i)
1156 result.v[i] = midpoint(a.v[i], b.v[i]);
1166template <
typename T,
int N>
1174 T
const tmp = T(1.0) / (
f.a *
f.a + g.
a * g.
a);
1189template <
typename T,
int N>
1197template <
typename T,
int N>
1200 T
const tmp = g *
pow(
f.a, g - T(1.0));
1215template <
typename T,
int N>
1230 for (
int i = 0; i < N; i++)
1235 result.
v[i] = std::numeric_limits<T>::quiet_NaN();
1242 T
const tmp =
pow(
f, g.
a);
1286template <
typename T,
int N>
1308 T
const tmp = g.
a *
pow(
f.a, g.
a - T(1.0));
1310 for (
int i = 0; i < N; i++)
1315 result.
v[i] = T(std::numeric_limits<double>::quiet_NaN());
1324 T
const tmp1 =
pow(
f.a, g.
a);
1325 T
const tmp2 = g.
a *
pow(
f.a, g.
a - T(1.0));
1326 T
const tmp3 = tmp1 *
log(
f.a);
1327 result =
Jet<T, N>(tmp1, tmp2 *
f.v + tmp3 * g.
v);
1337template <
typename T,
int N>
1340 s <<
"[" << z.
a <<
" ; ";
1341 for (
int i = 0; i < N; ++i)
1356template <
typename T,
int N>
1357struct numeric_limits<
wolf::autodiff::Jet<T, N>>
1359 static constexpr bool is_specialized =
true;
1360 static constexpr bool is_signed = std::numeric_limits<T>::is_signed;
1361 static constexpr bool is_integer = std::numeric_limits<T>::is_integer;
1362 static constexpr bool is_exact = std::numeric_limits<T>::is_exact;
1363 static constexpr bool has_infinity = std::numeric_limits<T>::has_infinity;
1364 static constexpr bool has_quiet_NaN = std::numeric_limits<T>::has_quiet_NaN;
1365 static constexpr bool has_signaling_NaN = std::numeric_limits<T>::has_signaling_NaN;
1366 static constexpr bool is_iec559 = std::numeric_limits<T>::is_iec559;
1367 static constexpr bool is_bounded = std::numeric_limits<T>::is_bounded;
1368 static constexpr bool is_modulo = std::numeric_limits<T>::is_modulo;
1374 static constexpr std::float_denorm_style has_denorm = std::numeric_limits<T>::has_denorm;
1376 static constexpr std::float_round_style round_style = std::numeric_limits<T>::round_style;
1378 static constexpr int digits = std::numeric_limits<T>::digits;
1379 static constexpr int digits10 = std::numeric_limits<T>::digits10;
1380 static constexpr int max_digits10 = std::numeric_limits<T>::max_digits10;
1381 static constexpr int radix = std::numeric_limits<T>::radix;
1382 static constexpr int min_exponent = std::numeric_limits<T>::min_exponent;
1383 static constexpr int min_exponent10 = std::numeric_limits<T>::max_exponent10;
1384 static constexpr int max_exponent = std::numeric_limits<T>::max_exponent;
1385 static constexpr int max_exponent10 = std::numeric_limits<T>::max_exponent10;
1386 static constexpr bool traps = std::numeric_limits<T>::traps;
1387 static constexpr bool tinyness_before = std::numeric_limits<T>::tinyness_before;
1434template <
typename T,
int N>
1435struct NumTraits<
wolf::autodiff::Jet<T, N>>
1449 return Real(std::numeric_limits<T>::epsilon());
1454 return NumTraits<T>::digits10();
1458 return NumTraits<T>::max_digits10();
1470 HasFloatingPoint = 1,
1471 RequireInitialization = 1
1474 template <
bool Vectorized>
1479#if defined(EIGEN_VECTORIZE_AVX)
1493 return Real((std::numeric_limits<T>::max)());
1497 return Real(-(std::numeric_limits<T>::max)());
1507template <
typename BinaryOp,
typename T,
int N>
1508struct ScalarBinaryOpTraits<
wolf::autodiff::Jet<T, N>, T, BinaryOp>
1512template <
typename BinaryOp,
typename T,
int N>
1513struct ScalarBinaryOpTraits<T,
wolf::autodiff::Jet<T, N>, BinaryOp>
Namespace extending Eigen definitions.
Definition: wolf.h:94
constexpr decltype(auto) AsScalar(T &&value) noexcept
Definition: jet_traits.h:112
Definition: integer_sequence_algorithm.h:50
Jet< T, N > cbrt(const Jet< T, N > &f)
Definition: jet.h:718
Jet< T, N > abs(const Jet< T, N > &f)
Definition: jet.h:531
Jet< T, N > operator*(const Jet< T, N > &f, const Jet< T, N > &g)
Definition: jet.h:356
Jet< T, N > log10(const Jet< T, N > &f)
Definition: jet.h:583
Jet< T, N > asin(const Jet< T, N > &f)
Definition: jet.h:648
decltype(auto) fmin(const Lhs &x, const Rhs &y)
Definition: jet.h:841
bool IsNormal(double x)
Definition: jet.h:524
Jet< T, N > expm1(const Jet< T, N > &f)
Definition: jet.h:608
Jet< T, N > log2(const Jet< T, N > &f)
Definition: jet.h:735
bool isgreaterequal(const Lhs &f, const Rhs &g)
Definition: jet.h:1049
Jet< T, N > sin(const Jet< T, N > &f)
Definition: jet.h:641
Jet< T, N > erfc(const Jet< T, N > &x)
Definition: jet.h:893
bool IsInfinite(double x)
Definition: jet.h:520
bool IsNaN(double x)
Definition: jet.h:522
Jet< T, N > tanh(const Jet< T, N > &f)
Definition: jet.h:687
Jet< T, N > operator/(const Jet< T, N > &f, const Jet< T, N > &g)
Definition: jet.h:374
Jet< T, N > const & operator+(const Jet< T, N > &f)
Definition: jet.h:305
Jet< T, N > copysign(const Jet< T, N > &f, const Jet< T, N > g)
Definition: jet.h:558
bool isnormal(const Jet< T, N > &f)
Definition: jet.h:995
double BesselJ0(double x)
Definition: jet.h:905
bool islessgreater(const Lhs &f, const Rhs &g)
Definition: jet.h:1038
decltype(auto) fdim(const Lhs &f, const Rhs &g)
Definition: jet.h:864
N & f
Definition: jet.h:1085
bool isfinite(const Jet< T, N > &f)
Definition: jet.h:973
bool isunordered(const Lhs &f, const Rhs &g)
Definition: jet.h:1058
Jet< T, N > tan(const Jet< T, N > &f)
Definition: jet.h:656
Jet< T, N > floor(const Jet< T, N > &f)
Definition: jet.h:699
double BesselJn(int n, double x)
Definition: jet.h:917
Jet< T, N > atan(const Jet< T, N > &f)
Definition: jet.h:665
bool islessequal(const Lhs &f, const Rhs &g)
Definition: jet.h:1027
Jet< T, N > exp(const Jet< T, N > &f)
Definition: jet.h:600
bool isless(const Lhs &f, const Rhs &g)
Definition: jet.h:1005
bool signbit(const Jet< T, N > &f)
Definition: jet.h:1074
Jet< T, N > cosh(const Jet< T, N > &f)
Definition: jet.h:680
Jet< T, N > fma(const Jet< T, N > &x, const Jet< T, N > &y, const Jet< T, N > &z)
Definition: jet.h:778
int fpclassify(const Jet< T, N > &f)
Definition: jet.h:1067
WOLF_AUTODIFF_DEPRECATED_WITH_MSG("wolf::autodiff::IsFinite will be removed in a future Ceres Solver release. Please " "use wolf::autodiff::isfinite.") inline bool IsFinite(const Jet< T
double BesselJ1(double x)
Definition: jet.h:911
Jet< T, N > atan2(const Jet< T, N > &g, const Jet< T, N > &f)
Definition: jet.h:1167
Jet< T, N > erf(const Jet< T, N > &x)
Definition: jet.h:878
std::ostream & operator<<(std::ostream &s, const Jet< T, N > &z)
Definition: jet.h:1338
Jet< T, N > operator-(const Jet< T, N > &f)
Definition: jet.h:314
bool IsFinite(double x)
Definition: jet.h:518
Jet< T, N > norm(const Jet< T, N > &f)
Definition: jet.h:1190
Jet< T, N > log1p(const Jet< T, N > &f)
Definition: jet.h:592
Jet< T, N > hypot(const Jet< T, N > &x, const Jet< T, N > &y)
Definition: jet.h:746
bool isnan(const Jet< T, N > &f)
Definition: jet.h:987
bool isinf(const Jet< T, N > &f)
Definition: jet.h:980
Jet< T, N > log(const Jet< T, N > &f)
Definition: jet.h:575
WOLF_AUTODIFF_DEFINE_JET_COMPARISON_OPERATOR(<) WOLF_AUTODIFF_DEFINE_JET_COMPARISON_OPERATOR(<
Jet< T, N > exp2(const Jet< T, N > &f)
Definition: jet.h:726
decltype(auto) fmax(const Lhs &x, const Rhs &y)
Definition: jet.h:818
Jet< T, N > pow(const Jet< T, N > &f, const Jet< T, N > &g)
Definition: jet.h:1287
Jet< T, N > pow(const Jet< T, N > &f, double g)
Definition: jet.h:1198
bool isgreater(const Lhs &f, const Rhs &g)
Definition: jet.h:1016
Jet< T, N > sqrt(const Jet< T, N > &f)
Definition: jet.h:617
Jet< T, N > cos(const Jet< T, N > &f)
Definition: jet.h:626
Jet< T, N > ceil(const Jet< T, N > &f)
Definition: jet.h:709
Jet< T, N > acos(const Jet< T, N > &f)
Definition: jet.h:633
Jet< T, N > sinh(const Jet< T, N > &f)
Definition: jet.h:673
Jet< T, N > hypot(const Jet< T, N > &x, const Jet< T, N > &y, const Jet< T, N > &z)
Definition: jet.h:762
Definition: capture_base.h:23
#define WOLF_AUTODIFF_DISABLE_DEPRECATED_WARNING
Definition: port.h:94
#define WOLF_AUTODIFF_RESTORE_DEPRECATED_WARNING
Definition: port.h:95
static int digits10()
Definition: jet.h:1452
static Real highest()
Definition: jet.h:1491
static int max_digits10()
Definition: jet.h:1456
@ IsSigned
Definition: jet.h:1465
static wolf::autodiff::Jet< T, N > dummy_precision()
Definition: jet.h:1442
static Real epsilon()
Definition: jet.h:1447
static Real lowest()
Definition: jet.h:1495
static constexpr wolf::autodiff::Jet< T, N > min WOLF_AUTODIFF_PREVENT_MACRO_SUBSTITUTION() noexcept
Definition: jet.h:1389
static constexpr wolf::autodiff::Jet< T, N > max WOLF_AUTODIFF_PREVENT_MACRO_SUBSTITUTION() noexcept
Definition: jet.h:1422
static constexpr wolf::autodiff::Jet< T, N > lowest() noexcept
Definition: jet.h:1393
static constexpr wolf::autodiff::Jet< T, N > signaling_NaN() noexcept
Definition: jet.h:1413
static constexpr wolf::autodiff::Jet< T, N > epsilon() noexcept
Definition: jet.h:1397
static constexpr wolf::autodiff::Jet< T, N > infinity() noexcept
Definition: jet.h:1405
static constexpr wolf::autodiff::Jet< T, N > denorm_min() noexcept
Definition: jet.h:1417
static constexpr wolf::autodiff::Jet< T, N > quiet_NaN() noexcept
Definition: jet.h:1409
static constexpr wolf::autodiff::Jet< T, N > round_error() noexcept
Definition: jet.h:1401
Jet< T, N > & operator*=(const T &s)
Definition: jet.h:282
Jet< T, N > & operator/=(const Jet< T, N > &y)
Definition: jet.h:266
Jet< T, N > & operator*=(const Jet< T, N > &y)
Definition: jet.h:261
EIGEN_STRONG_INLINE Jet(const T &a, const Eigen::DenseBase< Derived > &v)
Definition: jet.h:247
Jet< T, N > & operator/=(const T &s)
Definition: jet.h:287
Jet< T, N > & operator+=(const Jet< T, N > &y)
Definition: jet.h:251
Jet< T, N > & operator+=(const T &s)
Definition: jet.h:272
Jet()
Definition: jet.h:227
Jet(const T &value)
Definition: jet.h:230
@ DIMENSION
Definition: jet.h:219
Jet< T, N > & operator-=(const Jet< T, N > &y)
Definition: jet.h:256
T Scalar
Definition: jet.h:220
Jet(const T &value, int k)
Definition: jet.h:236
Eigen::Matrix< T, N, 1 > v
Definition: jet.h:296
Jet< T, N > & operator-=(const T &s)
Definition: jet.h:277